@extends('layouts.default') @section('main')
    <script type="text/javascript" src="{{URL::asset('js/')}}/ajaxfileupload.js"></script>
    <script type="text/javascript" src="{{URL::asset('js/')}}/common.js"></script>
    <script src="{{URL::asset('js/My97DatePicker/')}}/WdatePicker.js"></script>

    <div id="content">
        <div id="content-header">
            <div id="breadcrumb">
                <a href="{{url('home')}}" title="返回首页" class="tip-bottom"><i
                            class="icon-home"></i> 首页</a>
                <a href="{{url('act/index')}}" class="tip-bottom">活动管理</a>
                <a href="#" class="current">新增活动</a>
            </div>
        </div>
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span9">
                    <div class="widget-box">
                        <div class="widget-title">
						<span class="icon"> <i class="icon-align-justify"></i>
						</span>
                            <h5>新增一个活动</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <form action="{{url('act/create')}}" method="post" id="adForm" class="form-horizontal">
                                <div class="control-group ">
                                    <label class="control-label">活动类型 :</label>
                                    <div class="controls ">
                                        <select  name="type_id" class=" span11" >
                                            <option value="">请选择</option>
                                            @foreach($types as $k)
                                                <option value="{{$k->id}}">{{$k->name}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">活动主题 :</label>
                                    <div class="controls">
                                        <input type="text" class="span11" name="title" placeholder="活动主题" />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">活动举行日期:</label>
                                    <div class="controls">
                                        <input type="text" class="span11" name="date" onfocus="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"
                                               placeholder="活动举行日期" />
                                    </div>
                                </div>

                                <!--<div class="control-group ">
                                    <label class="control-label">一等奖奖项 :</label>
                                    <div class="controls ">
                                        <select  name="aPrize" class=" span11" >
                                            <option value="">请选择</option>
                                            @foreach($aPrize as $k)
                                            <option value="{{$k->id}}">{{$k->name}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">一等奖数量 :</label>
                                    <div class="controls">
                                        <input type="text" class="span11" name="aNumeric" placeholder="一等奖数量" />
                                    </div>
                                </div>

                                <div class="control-group ">
                                    <label class="control-label">二等奖奖项 :</label>
                                    <div class="controls ">
                                        <select  name="bPrize" class=" span11" >
                                            <option value="">请选择</option>
                                            @foreach($bPrize as $k)
                                                <option value="{{$k->id}}">{{$k->name}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">二等奖数量 :</label>
                                    <div class="controls">
                                        <input type="text" class="span11" name="bNumeric" placeholder="二等奖数量" />
                                    </div>
                                </div>

                                <div class="control-group ">
                                    <label class="control-label">三等奖奖项 :</label>
                                    <div class="controls ">
                                        <select  name="cPrize" class=" span11" >
                                            <option value="" >请选择</option>
                                            @foreach($cPrize as $k)
                                                <option value="{{$k->id}}">{{$k->name}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">三等奖数量 :</label>
                                    <div class="controls">
                                        <input type="text" class="span11" name="cNumeric" placeholder="三等奖数量" />
                                    </div>
                                </div>

                                <div class="control-group" id="normal">
                                    <label class="control-label">普通奖项设置触发入口 :</label>
                                    <div class="controls" >
                                        <button type="button" id="add">点击继续添加普通奖项设置</button>
                                        <button type="button" id="delete">点击消除最下层的普通奖项设置</button>
                                    </div>
                                </div>-->

                                <input type="hidden" class="span11" name="formType" value="create" />
                                <div class="form-actions">
                                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                    <button type="button" id="doSave" class="btn btn-success">创建</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="{{URL::asset('js/')}}/common.js"></script>

    <script>
        var n=1;
        var myNum=new Array('零','一', '二', '三', '四', '五');
        $("#add").click(function(){
            ajaxRequest({},"{{url('act/d-prize')}}", function(data){
                if(data.status){
                    var m  = data.message.length;
                    if(m<n){
                        alert('目前数据库中只有'+m+'个普通奖项，你最多可以添加'+m+'个普通奖项');
                        return;
                    }
                    var html='';
                    html+='<div class="normal">';
                    html+='<div class="control-group ">';
                    html+='<label class="control-label">普通奖奖项'+myNum[n]+' :</label>';
                    html+='<div class="controls ">';
                    html+='<select  name="normal'+n+'Prize" class=" span11" >';
                    html+=' <option value="">请选择</option>';
                    $.each(data.message, function(i, n) {
                        html += "<option value='"+n.id+"'>"+n.name+"</option>";
                    });
                    html+='</select>';
                    html+=' </div>';
                    html+='</div>';
                    html+='<div class="control-group">';
                    html+='<label class="control-label">普通奖'+myNum[n]+'数量 :</label>';
                    html+='<div class="controls">';
                    html+='<input type="text" class="span11" name="normal'+n+'Numeric" placeholder="普通奖'+myNum[n]+'数量" />';
                    html+='</div>';
                    html+='</div>';
                    html+='</div>';
                    $("#normal").before(html);
                    n++;
                }else{
                    alert(data.message);
                }
            });
        });

        $("#delete").click(function(){
            var now = $("#normal").prev();
            if(now.hasClass("normal")){
                now.remove();
                n--;
            }else{
                alert('已经没有普通奖项设置框可以用来消除了！');
                return ;
            }
        });



        $("#doSave").click(function(){
            ajaxRequest($('#adForm').serializeArray(),$('#adForm').attr('action'),function(data){
                if(data.status){
                    alert(data.message);
                    window.location.href = data.forwardUrl;
                }else{
                    alert(data.message);
                }
            });
        });

        $(function(){
            var index = 0; var n =0;var speed =1;
            var len =$(".proUl li").length;
            var time =setInterval(function(){
                index++;
                if(index ==11){
                    index =1;
                    n ++;
                    // speed =100-20*n;
                }
                $(".proUl li[data-id="+index+"]").addClass('opa1').siblings('li').removeClass('opa1');
            },100);
        });

    </script>
@stop
